<template>
    <div>
        <div class="crumbs">
            <el-breadcrumb separator="/">
                <el-breadcrumb-item>
                    <i class="el-icon-pie-chart"></i> 用户列表
                </el-breadcrumb-item>
            </el-breadcrumb>
        </div>
        <div class="container">
            <div class="handle-box">
                <el-input v-model="query.userName" prefix-icon="el-icon-search" clearable placeholder="请输入关键词" class="handle-input mr10"></el-input>
                <el-button type="primary" icon="el-icon-search" @click="handleSearch">搜索</el-button>
            </div>
            <el-table
                    :data="userList"
                    stripe
                    style="width: 100%">
                <el-table-column
                        prop="index"
                        label="序号"
                        align="center"
                        width="100">
                    <template slot-scope="scope">
                        {{scope.$index+1}}
                    </template>
                </el-table-column>
                <el-table-column
                        prop="userName"
                        label="用户名"
                        align="center"
                        width="180">
                </el-table-column>
                <el-table-column
                    prop="score"
                    label="积分"
                    align="center"
                    width="180">
                </el-table-column>
                <el-table-column
                        prop="data"
                        align="center"
                        label="头像(点击预览大图)">
                    <template slot-scope="scope">
                        <el-image
                                style="width: 50px; height: 50px"
                                :src="scope.row.userAvatarurl"
                                :preview-src-list="srcList">
                            <div slot="error" class="image-slot">
                                <i class="el-icon-picture-outline"></i>
                            </div>
                        </el-image>
                    </template>
                </el-table-column>
                <el-table-column
                        prop="userTime"
                        label="注册时间"
                        align="center"
                        width="180">
                </el-table-column>
            </el-table>
            <div class="pagination">
                <el-pagination
                        background
                        layout="sizes, total, prev, pager, next"
                        :current-page="query.pageIndex"
                        :page-size="query.pageSize"
                        :total="pageTotal"
                        @size-change="handleSizeChange"
                        @current-change="handlePageChange"
                ></el-pagination>
            </div>
        </div>
    </div>
</template>

<script>
export default {
    name: 'basecharts',
    components: {

    },
    data() {
        return {
            query: {
                userName:'',
                pageIndex: 1,
                pageSize: 10
            },
            userList: [],
            pageTotal: 0,
            srcList:[]
        };
    },
    created(){
      this.getData()
    },
    methods:{
        getData(){
            this.$axios.get(this.GLOBAL.httpUrl + "/user/select", {
                params: this.query
            }).then(res=>{
                this.pageTotal = res.data.data.totalCount;
                for(let i=0;i<res.data.data.resultList.length;i++){
                    this.srcList.push(res.data.data.resultList[i].userAvatarurl);
                    res.data.data.resultList[i].userTime = this.dateFormat(res.data.data.resultList[i].userTime);
                }
                this.userList = res.data.data.resultList
            })
        },
        // 分页导航
        handleSizeChange(val) {
            this.$set(this.query, 'pageSize', val);
            this.getData();
        },
        handlePageChange(val){
            this.$set(this.query, "pageIndex", val)
            this.getData();
        },
        // 触发搜索按钮
        handleSearch() {
            this.$set(this.query, 'pageIndex', 1);
            this.getData();
        },
    }
};
</script>

<style scoped>
.handle-box {
    margin-bottom: 20px;
}
.handle-input {
    width: 300px;
    display: inline-block;
}
.mr10 {
    margin-right: 10px;
}
.schart-box {
    display: inline-block;
    margin: 20px;
}
.schart {
    width: 600px;
    height: 400px;
}
.content-title {
    clear: both;
    font-weight: 400;
    line-height: 50px;
    margin: 10px 0;
    font-size: 22px;
    color: #1f2f3d;
}
</style>